package com.jp.knowledge.my.activity;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.jiayen.util.ToasUtil;
import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.logic.ShareLogic;
import com.jp.knowledge.model.UserData;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

import org.xutils.view.annotation.ViewInject;

/**
 * Created by 528787067@qq.com on 2017/5/9.
 */

public class InviteActivity extends SlidingActivity implements View.OnClickListener {

    @ViewInject(R.id.invite_friend_btn)
    private TextView editText;

    private ShareLogic shareLogic;

    @Override
    protected int getResourceId() {
        return R.layout.activity_invite;
    }

    @Override
    protected void init() {
        topName.setText("邀请好友");
        rightIcon.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        leftIcon.setOnClickListener(this);
        editText.setOnClickListener(this);

        final UserData userData = application.getUserData();
        shareLogic = new ShareLogic(mContext, new ShareBoardlistener() {
            @Override
            public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                if(snsPlatform.mShowWord.equals("share_copy_url")){
                    ToasUtil.toast(mContext, "复制成功");
                }else {
                    try {
                        ShareAction shareAction = new ShareAction((Activity) mContext).withText("分享个人信息").withTitle("荐识")
                                .withTargetUrl(userData.getPortrait())
                                .setPlatform(share_media)
                                .setCallback(shareLogic.umShareListener);
                        if (!share_media.equals(SHARE_MEDIA.SINA)) {
                            shareAction.withMedia(new UMImage(mContext,userData.getPortrait()));
                        }
                        shareAction.share();
                    }catch (Exception e){}
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.icon_left:
                finish();
                break;
            case R.id.invite_friend_btn:
                shareLogic.share();
                break;
        }
    }
}
